<?php
/**
 * 文件处理
 * 
 * @author: xudawei@staff.139.com
 * @copyright 139.com Inc
 * 
 */

class Picture {

	/**
	 * 将Base64字符串，保存成文件，并返回文件地址
	 *
	 * @param unknown_type $content
	 * @return unknown
	 */
	static public function saveFile($content) {
		$body = base64_decode($content);
		$filename = md5(substr($body, 0, 64));
		file_put_contents(TEMP . $filename, $body);
		if (IMAGETYPE_GIF == exif_imagetype(TEMP . $filename)) {
			rename(TEMP . $filename, TEMP . $filename . '.gif');
			return $filename . '.gif';	
		} else {
			self::remove($filename);
			return '';
		}
	}
	
	
	static public function remove($filename) {
		return @unlink(TEMP . $filename);
	}
}
